#ifndef CONFIGS_H
#define CONFIGS_H

#include <QObject>
#include <QListWidget>
#include <QString>
#include <QTableWidget>




class InputConfigs : public QObject
{
    Q_OBJECT

private:
    QString SerialName;
    int     SlaveID;
    int     DataAddress;
    int     DataLength;
    int     SaveAddress;
    QString infoStr;
    int     connect;


public:
    QListWidgetItem *listIcon;
    InputConfigs();
    void    setInputInfo(QString serialname,int id,int srcAddr,int length,int dstAddr,QString info);
    void    setInputSerialName(QString name);
    void    setInputSlaveID(int id);
    void    setInputDataAddress(int srcAddr);
    void    setInputDataLength(int length);
    void    setInputSaveAddress(int dstAddr);
    void    setInputInfoStr(QString info);
    QString getInputSerialName();
    int     getInputSlaveID();
    int     getInputDataAddress();
    int     getInputDataLength();
    int     getInputSaveAddress();
    QString getInputInfoStr();
    void    statechange();
    void    connected();
    static void loadFromInputs(QString file,QList<InputConfigs *> *inputs);
    static void loadFromInputs(QString file, QTableWidget *tw, QList<InputConfigs *> *inputs);
    static void saveToInputs(QString file, QTableWidget *tw);
    int getConnect() const;
    void setConnect(int value);

signals:
    void stateToggle(QListWidgetItem *listIcon);

};


class OutputConfigs: public QObject
{
    Q_OBJECT

private:
    QString SerialName;
    int     SlaveID;
    int     DataAddress;
    int     DataLength;
    int     StartAddr;
    int     connect;

public:
    QListWidgetItem *listIcon;
    OutputConfigs();
    void    setOutputInfo(QString serialname,int id,int srcAddr,int length,int startAddr);
    void    setOutputSerialName(QString name);
    void    setOutputSlaveID(int id);
    void    setOutputDataAddress(int srcAddr);
    void    setOutputDataLength(int length);
    void    setOutputStartAddr(int startAddr);
    QString getOutputSerialName();
    int     getOutputSlaveID();
    int     getOutputDataAddress();
    int     getOutputDataLength();
    int     getOutputStartAddr();
    void    connected();
    static void loadFromOutputs(QString file,QList<OutputConfigs *> *outputs);
    static void loadFromOutputs(QString file,QTableWidget *tw,QList<OutputConfigs *> *outputs);
    static void saveToOutputs(QString file, QTableWidget *tw);
    int getConnect() const;
    void setConnect(int value);

signals:
    void stateToggle(QListWidgetItem *listIcon);

};

class SerialConfigs: public QObject
{
    Q_OBJECT

private:
    QString Serial;
    int     Baud;
    char    Parity;
    int     DataBits;
    int     StopBits;
public:
    QList<InputConfigs *> inputs;
    QList<OutputConfigs *> outputs;



public:
    SerialConfigs();
    void setSerialInfo(QString serial, int baud, char parity, int databits,int stopbits);
    void setSerialName(QString serial);
    void setSerialBaud(int baud);
    void setSerialParity(char parity);
    void setSerialDataBits(int databits);
    void setSerialStopBits(int stopbits);
    QString getSerialName();
    int  getSerialBaud();
    char getSerialParity();
    int  getSerialDataBits();
    int  getSerialStopBits();
    void getSerialFromTW(QTableWidget *tw,int row);
    void setSerialToTW(QTableWidget *tw,int row);
    void saveSerialIni(QString file, int row);
    void loadSerialIni(QString file, int row);
    void insertIntoInputs(InputConfigs *ic);
    void insertIntoOutputs(OutputConfigs *oc);
    static void loadFromSerials(QString file,QList<SerialConfigs *> *serials);
    static void loadFromSerials(QString file,QTableWidget *tw,QList<SerialConfigs *> *serials);
    static void saveToSerials(QString file, QTableWidget *tw);
};




#endif // CONFIGS_H
